/* ************************************************************************** */ 
/* Example of a syndication feed reader using the Project Rome API with       */ 
/* BSF4ooRexx                                                                 */ 
/* current version of Rome: rome1.0.jar            https://rome.dev.java.net/ */ 
/* You need to implement this API plus the JDOM API                           */ 
/* jdom.jar  ,   you can find this at               https://jdom.org/        ; */ 
/*                                                                            */ 
/* This class retrieves a syndfeed from the web and prints it to the system   */ 
/* using the syndfeed Outout and the wirefeed Output                          */                      
/* created by Martin Stoppacher     date:   26.12.2009    (c) 2009            */ 
/* license:ÊÊÊÊLGPL 3.0ÊÊÊÊÊÊÊused versions: Java 1.6, ooRexx 4.0, Bsf4ooRexx */
/*             (Lesser Gnu Public License version 3.0),                       */ 
/*             cf. <http://www.gnu.org/licenses/lgpl.html>                    */ 
/* ************************************************************************** */ 

/* grafical part                                                              */ 
frame=.bsf~new("java.awt.Frame", "Please enter the url") 
frame~bsf.addEventListener( 'window', 'windowClosing', 'call BSF "exit"') 
frame~setLayout( .bsf~new("java.awt.FlowLayout") ) 

tf=.bsf~new("java.awt.TextField", "http://rss.orf.at/fm4.xml", 50) 

type=.bsf~new("java.awt.TextField", "rss_2.0", 50) 

but=.bsf~new('java.awt.Button', 'retrieve feed') 
but~bsf.addEventListener('action', '', ' call text tf,type ') 

lable1=.bsf~new('java.awt.Label', "Feed URL:") 
lable2=.bsf~new('java.awt.Label', "Feed Type:") 

frame~add(lable1) 
frame~add(tf) 
frame~add(lable2) 
frame~add(type) 
frame~add(but) 
 
frame~~pack~~show~~toFront 

do forever
INTERPRET .bsf~bsf.pollEventText 
if result="SHUTDOWN, REXX !" then leave 
end 
exit 

text: --procedure
use arg tf,type  
 
say hello this reads a syndfeed 
-- say please type in the url
-- pull url                                             /* optional url input */
--url="http://rss.orf.at/fm4.xml"
url = tf~getText 

typet= type~getText                              /* optional rss type parts */ 
--pull typet

typet="rss_2.0" 

feedUrl=.bsf~new("java.net.URL", url)               /* creating a URL object  */ 
say connecting__ || feedUrl~getAuthority() 

call Syssleep 1 

input=.bsf~new("com.sun.syndication.io.SyndFeedInput") 
/*  creates a SyndFeedInput , an independent object model  instance           */ 
xmlr=.bsf~new("com.sun.syndication.io.XmlReader", feedUrl) 
/*     Figures out the charset encoding of the XML document within the stream */ 

input~setXmlHealerOn(0)                                  /* set healer on off */ 
say input~getXmlHealerOn()                           /* checks for xml healer */ 

feed=input~build(xmlr)              /* Creates a SyndFeed out ouf the SFInput */ 
wfeed = feed~createWireFeed("rss_1.0")  /*  creates a WireFeed (abstract DM)  */ 
feed~setFeedType(typet)                /*   sets the feedtype of the SyndFeed  */ 

/*                      outputs from the SyndFeed, (independend object model) */ 
output=.bsf~new("com.sun.syndication.io.SyndFeedOutput") 
say output~outputString(feed,1)       /* usage of pritty print(0 yes or 1 no) */ 

say feed~getFeedType() 
say "-----" 

/*                          outputs from the WireFeed, (abstract data model)  */ 
output2=.bsf~new("com.sun.syndication.io.WireFeedOutput") 
say output2~outputString(wfeed) 
 
say wfeed~getFeedType() 
say "------" 
say done 

/* grafical part                                                              */ 

do forever
INTERPRET .bsf~bsf.pollEventText 
end 


::requires BSF.cls